﻿using Ease.EaseMission.Runtime;
using Ease.EaseNode.Editor.NodeView;
using UnityEngine.UIElements;

namespace Ease.EaseMission.Editor.View
{
    public class MsInspectorView : BaseSoInspectorView<MissioInspectorSo>, IUpdateSelection
    {
        public new class UxmlFactory : UxmlFactory<MsInspectorView, UxmlTraits>
        {
        }

        private BaseEaseNode lastNode = null;

        public void OnUpdateSelection(BaseEaseNode easeNode)
        {
            lastNode = easeNode;
            if (easeNode == null)
            {
                if (so == null)
                    return;
                so.Stage = null;
                so.Data = null;
                so.Step = null;
                return;
            }
            if (so == null)
                return;
            so.Data = easeNode.State.Data as MissionData;
            if (so.Data == null)
                so.Step = easeNode.State.Data as MissionStep;
            if (so.Step == null)
                so.Stage = easeNode.State.Data as MissionStage;
        }

        protected override void OnEnteredEditorMode()
        {
            base.OnEnteredEditorMode();
            OnUpdateSelection(lastNode);
        }
    }
}